#include "thread_freshport.h"
#include <QSerialPortInfo>
#include <QList>


Thread_FreshPort::Thread_FreshPort()
{
}

Thread_FreshPort::Thread_FreshPort(QComboBox *combo)
{
    ComboBox = combo;
}

Thread_FreshPort::~Thread_FreshPort()
{
}

void Thread_FreshPort::Thread_FreshPort::run()
{
    for(;;)
    {
        if(ComboBox->isEnabled())
        {
            QList<QSerialPortInfo> list = QSerialPortInfo::availablePorts();
            QStringList combox_texts,infoPortNames;
            combox_texts.clear();
            infoPortNames.clear();
            for(QSerialPortInfo info: list)
            {
                infoPortNames.append(info.portName());
            }
            for(int i=0;i<ComboBox->count();i++)
            {
                combox_texts.append(ComboBox->itemText(i));
            }

            if(combox_texts != infoPortNames)
            {
                emit FreshPort(infoPortNames);
            }

        }
        sleep(1);
    }
}
